package com.yyoa.entity;

import java.math.BigDecimal;
import java.time.LocalDate;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 商品
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name = "t_commodity")
public class Commodity extends Base {

	private static final long serialVersionUID = 1L;

	@Column(name = "name", nullable = false)
	private String name;
	// 型号
	@Column(name = "specification", nullable = false)
	private String specification;
	// 供货商
	@Column(name = "supplier")
	private String supplier;
	// 数量
	@Column(name = "amount", nullable = false)
	private Integer amount;
	// 库存
	@Column(name = "inventory", nullable = false)
	private Integer inventory;
	// 单价
	@Column(name = "unit_price", nullable = false)
	private BigDecimal unitPrice;
	// 总价
	@Column(name = "total_price")
	private BigDecimal totalPrice;
	// 进货日期
	@Column(name = "arrival_date", nullable = false)
	private LocalDate arrivalDate;
	// 备注
	@Column(name = "remark")
	private String remark;

	/**
	 * 
	 * @ManyToOne：多对一
	 * 
	 *                cascade：级联
	 * 
	 *                fetch = FetchType.LAZY,延迟加载策略,如果不想延迟加载可以用FetchType .EAGER
	 *
	 */
	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
			CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinColumn(name = "emboitement_id")
	private Emboitement emboitement;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSpecification() {
		return specification;
	}

	public void setSpecification(String specification) {
		this.specification = specification;
	}

	public String getSupplier() {
		return supplier;
	}

	public void setSupplier(String supplier) {
		this.supplier = supplier;
	}

	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	public Integer getInventory() {
		return inventory;
	}

	public void setInventory(Integer inventory) {
		this.inventory = inventory;
	}

	public BigDecimal getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}

	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}

	public LocalDate getArrivalDate() {
		return arrivalDate;
	}

	public void setArrivalDate(LocalDate arrivalDate) {
		this.arrivalDate = arrivalDate;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Emboitement getEmboitement() {
		return emboitement;
	}

	public void setEmboitement(Emboitement emboitement) {
		this.emboitement = emboitement;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((amount == null) ? 0 : amount.hashCode());
		result = prime * result
				+ ((arrivalDate == null) ? 0 : arrivalDate.hashCode());
		result = prime * result
				+ ((emboitement == null) ? 0 : emboitement.hashCode());
		result = prime * result
				+ ((inventory == null) ? 0 : inventory.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((remark == null) ? 0 : remark.hashCode());
		result = prime * result
				+ ((specification == null) ? 0 : specification.hashCode());
		result = prime * result
				+ ((supplier == null) ? 0 : supplier.hashCode());
		result = prime * result
				+ ((totalPrice == null) ? 0 : totalPrice.hashCode());
		result = prime * result
				+ ((unitPrice == null) ? 0 : unitPrice.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Commodity other = (Commodity) obj;
		if (amount == null) {
			if (other.amount != null)
				return false;
		} else if (!amount.equals(other.amount))
			return false;
		if (arrivalDate == null) {
			if (other.arrivalDate != null)
				return false;
		} else if (!arrivalDate.equals(other.arrivalDate))
			return false;
		if (emboitement == null) {
			if (other.emboitement != null)
				return false;
		} else if (!emboitement.equals(other.emboitement))
			return false;
		if (inventory == null) {
			if (other.inventory != null)
				return false;
		} else if (!inventory.equals(other.inventory))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (remark == null) {
			if (other.remark != null)
				return false;
		} else if (!remark.equals(other.remark))
			return false;
		if (specification == null) {
			if (other.specification != null)
				return false;
		} else if (!specification.equals(other.specification))
			return false;
		if (supplier == null) {
			if (other.supplier != null)
				return false;
		} else if (!supplier.equals(other.supplier))
			return false;
		if (totalPrice == null) {
			if (other.totalPrice != null)
				return false;
		} else if (!totalPrice.equals(other.totalPrice))
			return false;
		if (unitPrice == null) {
			if (other.unitPrice != null)
				return false;
		} else if (!unitPrice.equals(other.unitPrice))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Commodity [name=" + name + ", specification=" + specification
				+ ", supplier=" + supplier + ", amount=" + amount
				+ ", inventory=" + inventory + ", unitPrice=" + unitPrice
				+ ", totalPrice=" + totalPrice + ", arrivalDate=" + arrivalDate
				+ ", remark=" + remark + ", emboitement=" + emboitement + "]";
	}

}
